import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;

@WebServlet("/w")
public class test1 extends HttpServlet{
    private static final long serialVersionUID = 1L;
    static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
    public test1() {
        super();
        // TODO Auto-generated constructor stub
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException {
        Connection conn;
        Statement stmt ;
        response.setContentType("text/html;charset=UTF-8");
        String name0 = request.getParameter("ss");
        String password0 = request.getParameter("pa");

        PrintWriter out = response.getWriter();
        try {
            Class.forName(JDBC_DRIVER);
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC","root","123456");
            stmt = conn.createStatement();
            String sql="INSERT INTO pass (name,password) value (\""+name0+"\","+Integer.parseInt(password0)+")";
            stmt.executeUpdate(sql);
            stmt.close();
            conn.close();
            RequestDispatcher rd=request.getRequestDispatcher("");
            rd.forward(request, response);
        } catch (ClassNotFoundException | SQLException | ServletException e) {
            e.printStackTrace();
            out.println("注册失败");
        }
    }
}
